package com.atguigu.day19.work;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Work2 {
    public static void main(String[] args) {
        ArrayList<Integer> lotNumList=lotNum();
        System.out.println("开始");
        ArrayList<Integer> inputList=inputNum();
        System.out.println("输入的号码为:");
        int count=countNum(inputList,lotNumList);
        System.out.println("乐透号码:"+lotNumList);
        System.out.println("猜中了:"+count+"个数字");
    }
    public static int countNum(ArrayList<Integer> inputList,ArrayList<Integer> lotNumList){
        int count =0;
        for (int i = 0; i < inputList.size(); i++) {
             Object num=inputList.get(i);
             if (lotNumList.contains(num)){
                 count++;
             }
        }
        return count;
    }
    public static ArrayList<Integer> inputNum(){
        ArrayList<Integer> list=new ArrayList<>();
        Scanner input=new Scanner(System.in);
        for (int i = 0;i<10;) {
             System.out.println("请输入第"+(i+1)+"个数字(1-50):");
            int num=input.nextInt();
            if (num>1&&num<=50&&!list.contains(num)){
                list.add(num);
                i++;
            }else{
                System.out.println("超过(1-50)的范围,重新输入");
            }
        }
        input.close();
        return list;
    }
    public static ArrayList<Integer> lotNum(){
        ArrayList<Integer> list=new ArrayList<>();
        Random r=new Random();
        for (int i=0;i<10;){
            int num=r.nextInt(50)+1;
            if(!list.contains(num)){
                list.add(num);
                i++;
            }
        }
        return list;
    }
}
